<?php

namespace App\Http\Resources\Activity\B;

use App\Http\Resources\BaseResource;
use App\Models\Activity\ActivityModel;
use Illuminate\Http\Request;

class ActivityDataListResource extends BaseResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request $request
     * @return array
     */
    public function toArray($request): array
    {
        return [
            "id"               => $this->id,
            "name"             => $this->name,
            "activityType"     => $this->activityType,
            "activityTypeText" => ActivityModel::ACTIVITY_TYPE_TEXT[$this->activityType] ?? "",
            "actions"          => $this->actionRel->map(function ($item) {
                $item['goodsInfo']     = json_decode($item['goodsInfo'] ?? '[]', true);
                $item['price']         = $item['price'] ?? 0;
                $item['originalPrice'] = $item['originalPrice'] ?? 0;

                return $item;
            }),
            "expireType"       => $this->expireType,
            "expireTypeText"   => ActivityModel::EXPIRE_TYPE_TEXT[$this->expireType] ?? "",
            "startTime"        => formatDate($this->startTime, ""),
            "endTime"          => formatDate($this->endTime, ""),
            "status"           => $this->status,
            "statusText"       => ActivityModel::STATUS_TEXT[$this->status] ?? "",
            "canJoinCount"     => $this->canJoinCount,
            "hasJoinCount"     => $this->hasJoinCount,
            "reviewCount"      => $this->reviewCount,
            "feedbackCount"    => $this->feedbackCount,
            "updatedAtText"    => $this->updatedAt->format("Y-m-d H:i:s"),
        ];
    }
}
